<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>场馆-demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <script th:src="@{/js/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/js/bootstrap.bundle.min.js}"></script>
    <script th:src="@{/js/jquery.twbsPagination.js}"></script>
    <style type="text/css">
        body{
            background-color: #f5f5f5;
            padding-top: 80px;
        }
        html {
            overflow-y: scroll;
        }
        :root {
            overflow-y: auto;
            overflow-x: hidden;
        }
        :root body {
            position: absolute;
        }
        body {
            width: 100vw;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div th:include="layout/header :: header(user=${session.user},flag=${session.user}!=null,page='venue_list')"></div>

<main role="main" class="container">
    <div class="card bg-white rounded shadow">
        <div class="card-header py-3 text-center bg-info text-light">
            <h5 class="card-title mb-0">场馆信息</h5>
        </div>
        <ul class="list-group pt-2 px-3" id="content">
<!--            <li class="list-group-item px-3 pt-3 border-0" th:each="venue : ${venue_list}">-->
<!--                <div class="media border-bottom border-gray pb-3">-->
<!--                    <div class="media-left mr-3">-->
<!--                        <img th:src="${venue.picture}"-->
<!--                             alt="" height="100px" width="100px">-->
<!--                    </div>-->
<!--                    <div class="media-body">-->
<!--                        <h5 class="media-heading font-weight-bold pb-3">-->
<!--                            <a th:href="@{venue}" th:method="post" th:text="${venue.venueName}">场馆A</a>-->
<!--                        </h5>-->
<!--                        <h6 class="d-flex">-->
<!--                            <p class="font-weight-bold mb-0">场馆位置：</p>-->
<!--                            <p class="mb-0" th:text="${venue.address}">上海市中心人民广场的南侧黄浦区人民大道201号</p>-->
<!--                        </h6>-->
<!--                        <h6 class="d-flex">-->
<!--                            <p class="font-weight-bold mb-0">开放时间：</p>-->
<!--                            <p class="mb-0" th:text="${venue.open_time}+'~'+${venue.close_time}">09:00 a.m. ~ 17:00 p.m.</p>-->
<!--                        </h6>-->
<!--                        <h6 class="d-flex">-->
<!--                            <p class="font-weight-bold mb-0">租金：</p>-->
<!--                            <p class="mb-0" th:text="${venue.price}">￥300/h</p>-->
<!--                        </h6>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </li>-->
        </ul>
        <div class="d-flex justify-content-center mt-2" id="pagination-demo"></div>


    </div>

</main>

<div th:include="layout/footer :: Footer"></div>
<script type="text/javascript">
    // $(document).ready(function () {
    //     getPage(1);
    // });

    $('#pagination-demo').twbsPagination({
        totalPages: [[${total}]],
        visiblePages: 5,
        onPageClick: function (event, page) {
            getPage(page);
        }
    });

    function getPage(page){
        $.ajax({//根据page去后台加载数据
            url : "/venuelist/getVenueList",
            type : "get",
            dataType : "json",
            data : {"page" : page},
            success : function(data) {
                appendHtml(data.content);//处理数据
                console.log(data);
            }
        });
    }
    function appendHtml(list) {//此函数用于处理后台返回的数据，根据自己需求来实现页面拼接
        let tableShow = '';
        for (let i = 0; i < list.length; i++) {
            tableShow += '<li class="list-group-item px-3 pt-3 border-0">\n' +
                '                <div class="media border-bottom border-gray pb-3">\n' +
                '                    <div class="media-left mr-3">\n';
            if(list[i].picture == '')
                tableShow += '<img src="venue.jpg" alt="" height="100px" width="100px">\n';
            else
                tableShow += '<img src="'+list[i].picture+'" alt="" height="100px" width="100px">\n';
            tableShow += '</div>\n' +
                '                    <div class="media-body">\n' +
                '                        <h5 class="media-heading font-weight-bold pb-3">\n' +
                '                            <a href="/venue?venueID='+list[i].venueID+'" target="_blank">'+list[i].venueName+'</a>\n' +
                '                        </h5>\n' +
                '                        <h6 class="d-flex">\n' +
                '                            <p class="font-weight-bold mb-0">场馆位置：</p>\n' +
                '                            <p class="mb-0">'+list[i].address+'</p>\n' +
                '                        </h6>\n' +
                '                        <h6 class="d-flex">\n' +
                '                            <p class="font-weight-bold mb-0">开放时间：</p>\n' +
                '                            <p class="mb-0">'+list[i].open_time+' ~ '+list[i].close_time+'</p>\n' +
                '                        </h6>\n' +
                '                        <h6 class="d-flex">\n' +
                '                            <p class="font-weight-bold mb-0">租金：</p>\n' +
                '                            <p class="mb-0">￥'+list[i].price+'/h</p>\n' +
                '                        </h6>\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '            </li>\n';
        }
        $('#content').html(tableShow);
    }

</script>
</body>
</html>